<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width: initial-scale=1.0" />
    <title>Document</title>
    <script>
      function size(n) {
        var max = Math.max.apply(Math, n);
        var min = Math.min.apply(Math, n);
        for (var i = 0; i <= n.length; i++) {
          if (n[i] == max) {
            var maxIndex = i;
            console.log("最大值为:" + max, "下标为:" + maxIndex);
          } else if (n[i] == min) {
            var minIndex = i;
            console.log("最小值为:" + min, "下标为:" + minIndex);
          }
        }

        if (maxIndex < minIndex) {
          var dele = n.splice(maxIndex, 1);
          console.log("需要删除的数字" + dele);
          console.log("返回新数组" + n);
          return size(n);
        }

        if (maxIndex > minIndex) {
          var date = max - min;
          console.log("最大利润为：" + date);
          return n;
        }
      }
      var classArray = [7, 1, 5, 3, 6, 4];

      size(classArray);
    </script>
  </head>
  <body></body>
</html>
